package cloud.zhixinglu.www.spring.boot.druid.controller;


import cloud.zhixinglu.www.spring.boot.druid.entity.TestEntity;
import cloud.zhixinglu.www.spring.boot.druid.service.TestService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 *  控制层。
 *
 * @author WeiXin
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/druidTest/")
public class DruidController {

    @Resource
    private TestService testService;

    /**
     * 根据主键获取详细信息。
     *
     * @param operationId {@link String} 唯一操作ID
     * @return 详情
     */
    @GetMapping("getInfo/{operationId}")
    public TestEntity getInfo(@PathVariable String operationId) {
        TestEntity test = testService.getTestByOperationId(operationId);
        System.out.println(test);
        return test;
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfoList/{operationId}")
    public List<TestEntity> getInfoList(@PathVariable String operationId) {
        List<TestEntity> test = testService.getTestListByOperationId(operationId);
        System.out.println(test);
        return test;
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @GetMapping("getAllList")
    public List<TestEntity> getAllList() {
        return testService.selectListByLimit(100);
    }

}
